
/**
 * 加入购物车
 */
function buy(goodsId,amount){
  $.ajax({
		type:"post",
		url: "../custcontroller/goodsCustController/goods_buy",
		data: JSON.stringify({
			"goodsId":goodsId,
			"amount":amount,
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		success: function(data, textStatus) {
			debugger;
			if(data.success == true)
			{
				layer.msg("添加到购物车!", {time:800}, function(){
               location.reload();
            });
			}
			else if(data.success == false)
			{
            layer.msg(data.error, {time:800}, function(){

            });
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function countMyCart(){
  $.ajax({
		type:"post",
		url: "../custcontroller/goodsCustController/count_my_cart",
		dataType: 'json',
		success: function(data, textStatus) {
			debugger;
			if (data.success == true) {
			 $(".card_num").text(data.rows);
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function lessen(goodsId,amount){
    $.ajax({
		type:"post",
		url: "../custcontroller/goodsCustController/goods_lessen",
		data: JSON.stringify({
			"goodsId":goodsId,
			"amount":amount,
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		success: function(data, textStatus) {
			debugger;
			if(data.success == true)
			{
				layer.msg("减少购物车货品!", {time:800}, function(){
            location.reload();
        });
			}
			else if(data.success == false)
			{
        layer.msg(data.error, {time:800}, function(){
      });
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}
